package com.xsherl.leetcode.solution;

import java.util.LinkedList;

/**
 * @Author: sherl
 * @Date: 2021/5/24 20:53
 */
public class EvalRPN {

    public int evalRPN(String[] tokens) {
        LinkedList<Integer> ops = new LinkedList<>();
        for (String t: tokens){
            if ("+".equals(t)){
                int b = ops.pop();
                int a = ops.pop();
                ops.push(a + b);
            } else if ("-".equals(t)){
                int b = ops.pop();
                int a = ops.pop();
                ops.push(a - b);
            } else if ("*".equals(t)){
                int b = ops.pop();
                int a = ops.pop();
                ops.push(a * b);
            } else if ("/".equals(t)){
                int b = ops.pop();
                int a = ops.pop();
                ops.push(a / b);
            } else {
                ops.push(Integer.valueOf(t));
            }
        }
        return ops.pop();
    }

}
